package com.yuantong.xyerp.rest.controller;

import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
import com.yuantong.xyerp.core.api.common.Constant;
import com.yuantong.xyerp.core.api.dto.ContractDto;
import com.yuantong.xyerp.core.api.form.QueryForm;
import com.yuantong.xyerp.core.provider.dao.ContractMapper;
import com.yuantong.xyerp.rest.controller.base.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Jianguo.Yin on 2021-08-06.
 */
@RestController
@RequestMapping("/purchase")
@Api(tags = "采购单管理")
public class PurchaseController extends BaseController {

    private final String businessType = "B";

    @Resource
    private ContractMapper contractMapper;


    private Map<String, ExcelExportEntity> getPurcpurchaseContractColumns() {
        Map<String, ExcelExportEntity> purchaseContractColumns = new HashMap<>();

        ExcelExportEntity exportEntity = new ExcelExportEntity("提交时间", "createTime", 40);
        exportEntity.setFormat("yyyy-MM-dd hh:mm");

        ExcelExportEntity exportEntity7 = new ExcelExportEntity("到货方式", "transportType",40);
        exportEntity7.setReplace(new String[]{"自提_S", "配送_D"});

        ExcelExportEntity exportEntity10 = new ExcelExportEntity("流程状态", "nextProcessState",40);
        exportEntity10.setReplace(new String[]{"仓库管理员审批_warehouseExamine","采购主管复审_managerReexamine",
                "财务主管复审_financeReexamine","采购内勤初审_officeExamine","保存_save","出纳审核（尾款）_cashierReexamine",
                "总裁审批_ceoExamine","采购主管初审_managerExamine","财务内勤初审_financeExamine","初审驳回_reject",
                "采购内勤复审_officeReexamine","完成_finish","出纳审核（预付款）_cashierExamine"});

        ExcelExportEntity exportEntity11 = new ExcelExportEntity("付款类型", "payType",40);
        exportEntity11.setReplace(new String[]{"预付款_0","尾款_1"});


        purchaseContractColumns.put("提交时间",exportEntity);
        purchaseContractColumns.put("合同编号",new ExcelExportEntity("合同编号", "contractNo",40));
        purchaseContractColumns.put("品类",new ExcelExportEntity("品类", "categoryName",40));
        purchaseContractColumns.put("采购编号",new ExcelExportEntity("采购编号", "docNo",40));
        purchaseContractColumns.put("供应商名称",new ExcelExportEntity("供应商名称", "merchantName",40));
        purchaseContractColumns.put("采购重量（吨）",new ExcelExportEntity("采购重量（吨）" ,"totalWeight",40));
        purchaseContractColumns.put("到货仓库",new ExcelExportEntity("到货仓库", "warehouseName",40));
        purchaseContractColumns.put("到货方式",exportEntity7);
        purchaseContractColumns.put("采购人员",new ExcelExportEntity("采购人员", "signName",40));
        purchaseContractColumns.put("创建人",new ExcelExportEntity("创建人", "creatorName",40));
        purchaseContractColumns.put("流程状态",exportEntity10);
        purchaseContractColumns.put("预付款（元）",new ExcelExportEntity("预付款（元）", "advancePayment",40));
        purchaseContractColumns.put("已付金额（元）",new ExcelExportEntity("已付金额（元）", "actualPayment",40));
        purchaseContractColumns.put("采购金额（元）",new ExcelExportEntity("采购金额（元）", "totalPayment",40));
        purchaseContractColumns.put("未付金额（元）",new ExcelExportEntity("未付金额（元）", "actualReceivable",40));
        purchaseContractColumns.put("付款类型",exportEntity11);
        purchaseContractColumns.put("入库重量（吨）",new ExcelExportEntity("入库重量（吨）" ,"actualWeight",40));
        return purchaseContractColumns;
    }

    // 关于自定义导出数据, 前端传dto 导出合同基本信息/采购单/销售单
    /**
     * 采购单导出
     */
    @ApiOperation(value = "采购单导出",httpMethod = "POST", produces = "application/octet-stream")
    @PostMapping(value = "/export/purchaseList", produces = "application/octet-stream;charset=utf-8")
    public void purchaseList(HttpServletResponse response,
                          HttpServletRequest request,
                          @ApiParam("查询参数") @RequestBody QueryForm queryForm) {
        // 加  个人数据 部门数据 全部数据 的查询条件
        String causeId = getCauseId(request);

        List<ExcelExportEntity> entity = new ArrayList<>();
        Map<String, ExcelExportEntity> map = getPurcpurchaseContractColumns();

        // 销售单汇总
        entity.add(map.get("提交时间"));
        entity.add(map.get("合同编号"));
        entity.add(map.get("品类"));
        entity.add(map.get("采购编号"));
        entity.add(map.get("供应商名称"));
        entity.add(map.get("采购重量（吨）"));
        entity.add(map.get("到货仓库"));
        entity.add(map.get("到货方式"));
        entity.add(map.get("采购人员"));
        entity.add(map.get("流程状态"));

        List<ContractDto> list = contractMapper.findAllByFuzzy(
                businessType, queryForm.getStateType(), queryForm.getStartTime(), queryForm.getEndTime(), queryForm.getFuzzy(), null, null, queryForm.getIds(),causeId);

        String fileName = "采购单列表";
        Workbook workbook = ExcelExportUtil
                .exportExcel(new ExportParams(fileName, fileName, ExcelType.HSSF), entity, list);

        ServletOutputStream outputStream = null;
        try {
            response.setContentType("application/octet-stream");
            //中文乱码
            response.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(fileName + ".xls", "UTF-8"));
            outputStream = response.getOutputStream();
            workbook.write(outputStream);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (null != outputStream) {
                try {
                    outputStream.flush();
                    outputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }


    /**
     * 采购内勤初审_officeExamine
     */
    @ApiOperation(value = "采购内勤初审导出",httpMethod = "POST", produces = "application/octet-stream")
    @PostMapping(value = "/export/purchaseOfficeExamine", produces = "application/octet-stream;charset=utf-8")
    public void purchaseOfficeExamine(HttpServletResponse response,
                          HttpServletRequest request,
                          @ApiParam("查询参数") @RequestBody QueryForm queryForm) {
        // 加  个人数据 部门数据 全部数据 的查询条件
        String causeId = getCauseId(request);

        String stateType = Constant.state_officeExamine;

        List<ExcelExportEntity> entity = new ArrayList<>();
        Map<String, ExcelExportEntity> map = getPurcpurchaseContractColumns();

        // 销售单汇总
        entity.add(map.get("提交时间"));
        entity.add(map.get("合同编号"));
        entity.add(map.get("品类"));
        entity.add(map.get("采购编号"));
        entity.add(map.get("供应商名称"));
        entity.add(map.get("采购重量（吨）"));
        entity.add(map.get("到货仓库"));
        entity.add(map.get("到货方式"));
        entity.add(map.get("采购人员"));

        List<ContractDto> list = contractMapper.findAllByFuzzy(
                businessType, stateType, queryForm.getStartTime(), queryForm.getEndTime(), queryForm.getFuzzy(), null, null, queryForm.getIds(),causeId);

        String fileName = "采购内勤初审列表";
        Workbook workbook = ExcelExportUtil
                .exportExcel(new ExportParams(fileName, fileName, ExcelType.HSSF), entity, list);

        ServletOutputStream outputStream = null;
        try {
            response.setContentType("application/octet-stream");
            //中文乱码
            response.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(fileName + ".xls", "UTF-8"));
            outputStream = response.getOutputStream();
            workbook.write(outputStream);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (null != outputStream) {
                try {
                    outputStream.flush();
                    outputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }


    /**
     * 采购主管初审_managerExamine
     */
    @ApiOperation(value = "采购主管初审导出",httpMethod = "POST", produces = "application/octet-stream")
    @PostMapping(value = "/export/managerExamine", produces = "application/octet-stream;charset=utf-8")
    public void purchaseManagerExamine(HttpServletResponse response,
                                      HttpServletRequest request,
                                      @ApiParam("查询参数") @RequestBody QueryForm queryForm) {
        // 加  个人数据 部门数据 全部数据 的查询条件
        String causeId = getCauseId(request);

        String stateType = Constant.state_managerExamine;

        List<ExcelExportEntity> entity = new ArrayList<>();
        Map<String, ExcelExportEntity> map = getPurcpurchaseContractColumns();

        // 销售单汇总
        entity.add(map.get("提交时间"));
        entity.add(map.get("合同编号"));
        entity.add(map.get("品类"));
        entity.add(map.get("采购编号"));
        entity.add(map.get("供应商名称"));
        entity.add(map.get("采购重量（吨）"));
        entity.add(map.get("到货仓库"));
        entity.add(map.get("到货方式"));
        entity.add(map.get("采购人员"));

        List<ContractDto> list = contractMapper.findAllByFuzzy(
                businessType, stateType, queryForm.getStartTime(), queryForm.getEndTime(), queryForm.getFuzzy(), null, null, queryForm.getIds(),causeId);

        String fileName = "采购主管初审列表";
        Workbook workbook = ExcelExportUtil
                .exportExcel(new ExportParams(fileName, fileName, ExcelType.HSSF), entity, list);

        ServletOutputStream outputStream = null;
        try {
            response.setContentType("application/octet-stream");
            //中文乱码
            response.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(fileName + ".xls", "UTF-8"));
            outputStream = response.getOutputStream();
            workbook.write(outputStream);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (null != outputStream) {
                try {
                    outputStream.flush();
                    outputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    /**
     * 财务内勤初审_financeExamine
     */
    @ApiOperation(value = "财务内勤初审导出",httpMethod = "POST", produces = "application/octet-stream")
    @PostMapping(value = "/export/financeExamine", produces = "application/octet-stream;charset=utf-8")
    public void purchaseFinanceExamine(HttpServletResponse response,
                                       HttpServletRequest request,
                                       @ApiParam("查询参数") @RequestBody QueryForm queryForm) {
        // 加  个人数据 部门数据 全部数据 的查询条件
        String causeId = getCauseId(request);

        String stateType = Constant.state_financeExamine;

        List<ExcelExportEntity> entity = new ArrayList<>();
        Map<String, ExcelExportEntity> map = getPurcpurchaseContractColumns();

        // 销售单汇总
        entity.add(map.get("提交时间"));
        entity.add(map.get("合同编号"));
        entity.add(map.get("品类"));
        entity.add(map.get("采购编号"));
        entity.add(map.get("供应商名称"));
        entity.add(map.get("采购重量（吨）"));
        entity.add(map.get("预付款（元）"));
        entity.add(map.get("到货仓库"));
        entity.add(map.get("到货方式"));
        entity.add(map.get("采购人员"));

        List<ContractDto> list = contractMapper.findAllByFuzzy(
                businessType, stateType, queryForm.getStartTime(), queryForm.getEndTime(), queryForm.getFuzzy(), null, null, queryForm.getIds(),causeId);

        String fileName = "财务内勤初审列表";
        Workbook workbook = ExcelExportUtil
                .exportExcel(new ExportParams(fileName, fileName, ExcelType.HSSF), entity, list);

        ServletOutputStream outputStream = null;
        try {
            response.setContentType("application/octet-stream");
            //中文乱码
            response.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(fileName + ".xls", "UTF-8"));
            outputStream = response.getOutputStream();
            workbook.write(outputStream);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (null != outputStream) {
                try {
                    outputStream.flush();
                    outputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    /**
     * 总裁审批_ceoExamine
     */
    @ApiOperation(value = "总裁审批导出",httpMethod = "POST", produces = "application/octet-stream")
    @PostMapping(value = "/export/ceoExamine", produces = "application/octet-stream;charset=utf-8")
    public void purchaseCeoExamine(HttpServletResponse response,
                                   HttpServletRequest request,
                                   @ApiParam("查询参数") @RequestBody QueryForm queryForm) {
        // 加  个人数据 部门数据 全部数据 的查询条件
        String causeId = getCauseId(request);

        String stateType = Constant.state_ceoExamine;

        List<ExcelExportEntity> entity = new ArrayList<>();
        Map<String, ExcelExportEntity> map = getPurcpurchaseContractColumns();

        // 销售单汇总
        entity.add(map.get("提交时间"));
        entity.add(map.get("品类"));
        entity.add(map.get("供应商名称"));
        entity.add(map.get("采购重量（吨）"));
        entity.add(map.get("采购金额（元）"));
        entity.add(map.get("付款类型"));
        entity.add(map.get("已付金额（元）"));
        entity.add(map.get("到货仓库"));
        entity.add(map.get("到货方式"));

        List<ContractDto> list = contractMapper.findAllByFuzzy(
                businessType, stateType, queryForm.getStartTime(), queryForm.getEndTime(), queryForm.getFuzzy(), null, null, queryForm.getIds(),causeId);

        for (ContractDto contractDto: list) {
            if (contractDto.getActualPayment().compareTo(contractDto.getAdvancePayment()) == 0) {
                contractDto.setPayType("0");
            }
            contractDto.setPayType("1");
        }

        String fileName = "总裁审批列表";
        Workbook workbook = ExcelExportUtil
                .exportExcel(new ExportParams(fileName, fileName, ExcelType.HSSF), entity, list);

        ServletOutputStream outputStream = null;
        try {
            response.setContentType("application/octet-stream");
            //中文乱码
            response.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(fileName + ".xls", "UTF-8"));
            outputStream = response.getOutputStream();
            workbook.write(outputStream);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (null != outputStream) {
                try {
                    outputStream.flush();
                    outputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    /**
     * 出纳审核（预付款）_cashierExamine
     */
    @ApiOperation(value = "出纳审核（预付款）导出",httpMethod = "POST", produces = "application/octet-stream")
    @PostMapping(value = "/export/cashierExamine1", produces = "application/octet-stream;charset=utf-8")
    public void purchaseCashierExamine1(HttpServletResponse response,
                                        HttpServletRequest request,
                                        @ApiParam("查询参数") @RequestBody QueryForm queryForm) {
        // 加  个人数据 部门数据 全部数据 的查询条件
        String causeId = getCauseId(request);

        String stateType = Constant.state_cashierExamine;

        List<ExcelExportEntity> entity = new ArrayList<>();
        Map<String, ExcelExportEntity> map = getPurcpurchaseContractColumns();

        // 销售单汇总
        entity.add(map.get("提交时间"));
        entity.add(map.get("合同编号"));
        entity.add(map.get("品类"));
        entity.add(map.get("采购编号"));
        entity.add(map.get("供应商名称"));
        entity.add(map.get("入库重量（吨）"));
        entity.add(map.get("已付金额（元）"));
        entity.add(map.get("到货仓库"));
        entity.add(map.get("到货方式"));
        entity.add(map.get("采购人员"));

        List<ContractDto> list = contractMapper.findAllByFuzzy(
                businessType, stateType, queryForm.getStartTime(), queryForm.getEndTime(), queryForm.getFuzzy(), null, null, queryForm.getIds(),causeId);

        String fileName = "出纳审核（预付款）列表";
        Workbook workbook = ExcelExportUtil
                .exportExcel(new ExportParams(fileName, fileName, ExcelType.HSSF), entity, list);

        ServletOutputStream outputStream = null;
        try {
            response.setContentType("application/octet-stream");
            //中文乱码
            response.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(fileName + ".xls", "UTF-8"));
            outputStream = response.getOutputStream();
            workbook.write(outputStream);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (null != outputStream) {
                try {
                    outputStream.flush();
                    outputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    /**
     * 采购内勤复审_officeReexamine
     */
    @ApiOperation(value = "采购内勤复审导出",httpMethod = "POST", produces = "application/octet-stream")
    @PostMapping(value = "/export/officeReexamine", produces = "application/octet-stream;charset=utf-8")
    public void purchaseOfficeReexamine(HttpServletResponse response,
                                        HttpServletRequest request,
                                        @ApiParam("查询参数") @RequestBody QueryForm queryForm) {
        // 加  个人数据 部门数据 全部数据 的查询条件
        String causeId = getCauseId(request);

        String stateType = Constant.state_officeReexamine;

        List<ExcelExportEntity> entity = new ArrayList<>();
        Map<String, ExcelExportEntity> map = getPurcpurchaseContractColumns();

        // 销售单汇总
        entity.add(map.get("提交时间"));
        entity.add(map.get("合同编号"));
        entity.add(map.get("品类"));
        entity.add(map.get("采购编号"));
        entity.add(map.get("供应商名称"));
        entity.add(map.get("入库重量（吨）"));
        entity.add(map.get("已付金额（元）"));
        entity.add(map.get("到货仓库"));
        entity.add(map.get("到货方式"));
        entity.add(map.get("采购人员"));

        List<ContractDto> list = contractMapper.findAllByFuzzy(
                businessType, stateType, queryForm.getStartTime(), queryForm.getEndTime(), queryForm.getFuzzy(), null, null, queryForm.getIds(),causeId);

        String fileName = "采购内勤复审列表";
        Workbook workbook = ExcelExportUtil
                .exportExcel(new ExportParams(fileName, fileName, ExcelType.HSSF), entity, list);

        ServletOutputStream outputStream = null;
        try {
            response.setContentType("application/octet-stream");
            //中文乱码
            response.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(fileName + ".xls", "UTF-8"));
            outputStream = response.getOutputStream();
            workbook.write(outputStream);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (null != outputStream) {
                try {
                    outputStream.flush();
                    outputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }


    /**
     * 采购主管复审_managerReexamine
     */
    @ApiOperation(value = "采购主管复审导出",httpMethod = "POST", produces = "application/octet-stream")
    @PostMapping(value = "/export/managerReexamine", produces = "application/octet-stream;charset=utf-8")
    public void purchaseManagerReexamine(HttpServletResponse response,
                                         HttpServletRequest request,
                                         @ApiParam("查询参数") @RequestBody QueryForm queryForm) {
        // 加  个人数据 部门数据 全部数据 的查询条件
        String causeId = getCauseId(request);

        String stateType = Constant.state_managerReexamine;

        List<ExcelExportEntity> entity = new ArrayList<>();
        Map<String, ExcelExportEntity> map = getPurcpurchaseContractColumns();

        // 销售单汇总
        entity.add(map.get("提交时间"));
        entity.add(map.get("合同编号"));
        entity.add(map.get("品类"));
        entity.add(map.get("采购编号"));
        entity.add(map.get("供应商名称"));
        entity.add(map.get("入库重量（吨）"));
        entity.add(map.get("已付金额（元）"));
        entity.add(map.get("到货仓库"));
        entity.add(map.get("到货方式"));
        entity.add(map.get("采购人员"));

        List<ContractDto> list = contractMapper.findAllByFuzzy(
                businessType, stateType, queryForm.getStartTime(), queryForm.getEndTime(), queryForm.getFuzzy(), null, null, queryForm.getIds(),causeId);

        String fileName = "采购主管复审列表";
        Workbook workbook = ExcelExportUtil
                .exportExcel(new ExportParams(fileName, fileName, ExcelType.HSSF), entity, list);

        ServletOutputStream outputStream = null;
        try {
            response.setContentType("application/octet-stream");
            //中文乱码
            response.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(fileName + ".xls", "UTF-8"));
            outputStream = response.getOutputStream();
            workbook.write(outputStream);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (null != outputStream) {
                try {
                    outputStream.flush();
                    outputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    /**
     * 财务主管复审_financeReexamine
     */
    @ApiOperation(value = "财务主管复审导出",httpMethod = "POST", produces = "application/octet-stream")
    @PostMapping(value = "/export/financeReexamine", produces = "application/octet-stream;charset=utf-8")
    public void purchaseFinanceReexamine(HttpServletResponse response,
                                         HttpServletRequest request,
                                         @ApiParam("查询参数") @RequestBody QueryForm queryForm) {
        // 加  个人数据 部门数据 全部数据 的查询条件
        String causeId = getCauseId(request);

        String stateType = Constant.state_financeReexamine;

        List<ExcelExportEntity> entity = new ArrayList<>();
        Map<String, ExcelExportEntity> map = getPurcpurchaseContractColumns();

        // 销售单汇总
        entity.add(map.get("提交时间"));
        entity.add(map.get("合同编号"));
        entity.add(map.get("品类"));
        entity.add(map.get("采购编号"));
        entity.add(map.get("供应商名称"));
        entity.add(map.get("入库重量（吨）"));
        entity.add(map.get("未付金额（元）"));
        entity.add(map.get("到货仓库"));
        entity.add(map.get("到货方式"));
        entity.add(map.get("采购人员"));

        List<ContractDto> list = contractMapper.findAllByFuzzy(
                businessType, stateType, queryForm.getStartTime(), queryForm.getEndTime(), queryForm.getFuzzy(), null, null, queryForm.getIds(),causeId);

        String fileName = "财务主管复审列表";
        Workbook workbook = ExcelExportUtil
                .exportExcel(new ExportParams(fileName, fileName, ExcelType.HSSF), entity, list);

        ServletOutputStream outputStream = null;
        try {
            response.setContentType("application/octet-stream");
            //中文乱码
            response.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(fileName + ".xls", "UTF-8"));
            outputStream = response.getOutputStream();
            workbook.write(outputStream);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (null != outputStream) {
                try {
                    outputStream.flush();
                    outputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    /**
     * 出纳审核（尾款）_cashierReexamine
     */
    @ApiOperation(value = "出纳审核（尾款）导出",httpMethod = "POST", produces = "application/octet-stream")
    @PostMapping(value = "/export/cashierReexamine", produces = "application/octet-stream;charset=utf-8")
    public void purchaseCashierReexamine(HttpServletResponse response,
                                         HttpServletRequest request,
                                         @ApiParam("查询参数") @RequestBody QueryForm queryForm) {
        // 加  个人数据 部门数据 全部数据 的查询条件
        String causeId = getCauseId(request);

        String stateType = Constant.state_cashierReexamine;

        List<ExcelExportEntity> entity = new ArrayList<>();
        Map<String, ExcelExportEntity> map = getPurcpurchaseContractColumns();

        // 销售单汇总
        entity.add(map.get("提交时间"));
        entity.add(map.get("合同编号"));
        entity.add(map.get("品类"));
        entity.add(map.get("采购编号"));
        entity.add(map.get("供应商名称"));
        entity.add(map.get("入库重量（吨）"));
        entity.add(map.get("未付金额（元）"));
        entity.add(map.get("到货仓库"));
        entity.add(map.get("到货方式"));
        entity.add(map.get("采购人员"));

        List<ContractDto> list = contractMapper.findAllByFuzzy(
                businessType, stateType, queryForm.getStartTime(), queryForm.getEndTime(), queryForm.getFuzzy(), null, null, queryForm.getIds(),causeId);

        String fileName = "出纳审核（尾款）列表";
        Workbook workbook = ExcelExportUtil
                .exportExcel(new ExportParams(fileName, fileName, ExcelType.HSSF), entity, list);

        ServletOutputStream outputStream = null;
        try {
            response.setContentType("application/octet-stream");
            //中文乱码
            response.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(fileName + ".xls", "UTF-8"));
            outputStream = response.getOutputStream();
            workbook.write(outputStream);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (null != outputStream) {
                try {
                    outputStream.flush();
                    outputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
